package at.ac.tuwien.mg.bean;

import java.io.Serializable;
import java.util.List;

import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;

import com.sun.jersey.api.client.AsyncWebResource;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

@XmlRootElement
public class Supplier implements Serializable {
	private static final long serialVersionUID = -1731916325455357122L;
	
	private String name;
	private String baseURL;
	private String offerSuffix;
	private String orderSuffix;
	private List<String> goods;
	
	public Supplier() {}
	
	public Supplier(String name, String baseURL, String offerSuffix, String orderSuffix, List<String> goods) {
		this.name = name; 
		this.baseURL = baseURL;
		this.offerSuffix = offerSuffix;
		this.orderSuffix = orderSuffix;
		this.goods = goods;
	}
	
	public void sendOffer(Offer offer) {
		ClientConfig cc = new DefaultClientConfig();
		Client c = Client.create(cc);
		AsyncWebResource r = c.asyncResource(baseURL + "/" + offerSuffix);
		r.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE);
		r.post(offer);
	}
	
	public void orderOffer(Offer offer) {
		ClientConfig cc = new DefaultClientConfig();
		Client c = Client.create(cc);
		WebResource r = c.resource(baseURL + "/" + orderSuffix);
		r.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE);
		r.post(offer);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getBaseURL() {
		return baseURL;
	}

	public void setBaseURL(String baseURL) {
		this.baseURL = baseURL;
	}

	public String getOfferSuffix() {
		return offerSuffix;
	}

	public void setOfferSuffix(String offerSuffix) {
		this.offerSuffix = offerSuffix;
	}

	public String getOrderSuffix() {
		return orderSuffix;
	}

	public void setOrderSuffix(String orderSuffix) {
		this.orderSuffix = orderSuffix;
	}

	public List<String> getGoods() {
		return goods;
	}

	public void setGoods(List<String> goods) {
		this.goods = goods;
	}
}
